#!/usr/bin/env python3
# vim:fileencoding=utf-8

'''
显示音乐文件的相关信息
'''

from lilypath import path
import stagger
from termcolor import colored
def red(str):
  return colored(str, 'red')
def yellow(str):
  return colored(str, 'yellow', attrs=['bold'])
def green(str):
  return colored(str, 'green', attrs=['bold'])

def main():
  d = path('~/音乐').expand()
  for i in d.traverse():
    if i.isfile():
      name = str(i)[len(str(d))+1:]
      info = []
      try:
        tag = stagger.read_tag(str(i))
      except stagger.errors.NoTagError:
        tag = ()
        info.append(red('没有标签信息'))

      if 'APIC' in tag:
        info.append(green('包含图片'))
      if 'COMM' in tag and 'TOP100' in tag.comment:
        info.append(yellow('来自谷歌'))
      print(name, '，'.join(info))

if __name__ == '__main__':
  main()

